CFLAGS += -DGIT_VERSION="\"$(shell LANG=C git log -n 1 | head -n 1 | awk '{print $$2}')\""
CFLAGS += -DGIT_BRANCH="\"$(shell LANG=C TZ='Asia/Shanghai' git branch | grep '^*' | awk '{print $$2;}')\""
CFLAGS += -DGIT_DATETIME="\"$(shell LANG=C TZ='Asia/Shanghai' date --date=@`git log -n 1 --date=raw | grep Date | cut -b 9- | awk '{print $$1}'` '+%F %T')\""
CFLAGS += -DGIT_STATUS="\"$(shell LANG=C git status | grep modified: | awk '{print $$2}')\""
CFLAGS += -DCOMPILE_DATETIME="\"$(shell LANG=C TZ='Asia/Shanghai' date '+%F %T')\""
CFLAGS += -Wall -g -I. -Ilog -Imemleak -Ilist -Iatomic -Iendian_portable -Ibacktrace
CFLAGS += -Ibuild_packet
CFLAGS += -O2
CFLAGS += -DDEBUG
CFLAGS += -DDBG_LIST
LDFLAGS += -lpcap
ifeq ($(shell uname -m), armv6l)
CFLAGS += -Imyuv
LDFLAGS += -rdynamic -Wl,-Bstatic -lz -Wl,-Bdynamic
else ifeq ($(shell grep '^ID=' /etc/os-release | cut -b 4-), arch)
CFLAGS += -Imyuv -Imbedtls-bin/include -Isodium-bin/include -Isqlite-bin/include
#LDFLAGS += --static
LDFLAGS += -rdynamic -lz -Lmbedtls-bin/lib/ -Lsodium-bin/lib/ -Lsqlite-bin/lib
else ifeq ($(shell uname -s), Linux)
CFLAGS += -Imyuv -Imbedtls-bin/include -Isodium-bin/include -Isqlite-bin/include
LDFLAGS += -rdynamic -lz -Lmbedtls-bin/lib/ -Lsodium-bin/lib/ -Lsqlite-bin/lib
else
CFLAGS +=  -Iuv-bin/windows-i686/include -Isqlite-bin/windows-i686/include -Isodium-bin/windows-i686/include/ -Imbedtls-bin/windows-i686/include/
LDFLAGS += -Luv-bin/windows-i686/lib -Lsqlite-bin/windows-i686/lib -Lsodium-bin/windows-i686/lib/ -Lmbedtls-bin/windows-i686/lib/
LDFLAGS += -lws2_32 -luv -static-libgcc -static-libstdc++ -Wl,-Bstatic -lwinpthread -lz -Wl,-Bdynamic
endif
CFLAGS += -DENABLE_RAW_SOCKET
LDFLAGS += -lpthread
LDFLAGS += -lz

TARGET = netspeeder

SRCS = $(wildcard *.c)
OBJS = $(patsubst %c, %o, $(SRCS))
DEPS = $(patsubst %c, %d, $(SRCS))

%.o: %.c
	$(CC) -c -MMD $(CFLAGS) $< -o $@

all: $(TARGET)

$(TARGET): ${OBJS}
	$(CC) -o $@ $(CFLAGS) $^ ${LDFLAGS}

install: $(TARGET)
	./install.sh

uninstall:
	./uninstall.sh

sinclude $(DEPS)

.PHONY: clean

clean:
	$(RM) $(TARGET) *.o *.d
